<?php
class IndexPresenter {
	private $contentRepository;
	private $view;
	private $userRepository;
	public function login($username, $password) {
		$user = $this->userRepository->checkUser ( $username, $password );
		if ($user != NULL) {
			Application::getInstance ()->setActiveUser ( $user );
			$this->view->loginSucceed ();
		} else {
			$this->view->loginError ();
		}
	}
	public function logout() {
		Application::getInstance ()->setActiveUser ( NULL );
		$this->view->logout ();
	}
	public function __construct(IndexView $view, IArticleRepository $contentRepository, IUserRepository $userRepository) {
		$this->view = $view;
		$this->contentRepository = $contentRepository;
		$this->userRepository = $userRepository;
	}
	public function getPreviews($from, $quantity) {
		return $this->contentRepository->getPreviews ( $from, $quantity );
	}
	public function getPreviewCount() {
		return $this->contentRepository->getCount ();
	}
}

?>